﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;

namespace Coronox.SkyShell
{
    public static class Extensions
    {

        public static void AddRange<T>(this ObservableCollection<T> oc, IEnumerable<T> collection)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }
            foreach (var item in collection)
            {
                oc.Add(item);
            }


        }


        // see http://stackoverflow.com/questions/3893866/umlaute-are-wrongly-encoded
        public static string ToUTF8(this string result)
        {
            if (string.IsNullOrEmpty(result))
                return string.Empty;

            Encoding ansi = Encoding.Default;
            Byte[] ansibytes = ansi.GetBytes(result);
            Encoding enc = new UTF8Encoding();
            string response = enc.GetString(ansibytes);

            return response;
        }


        public static string ToMailto(this string result)
        {
            if (string.IsNullOrEmpty(result))
                return string.Empty;

            string response = result;
            response = response.Replace(" ", "%20");
            response = response.Replace("&", "%26");
            return response;
        }

    }
}
